package com.ztgf.logistics.api.client.deppon;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.common.vo.UserVO;
import com.ztgf.shopping.models.dto.shop.ShopInfoDTO;
import com.ztgf.shopping.models.service.shop.IShopInfoService;
import com.ztgf.sys.models.service.ISessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.logistics.models.service.deppon.ILogisticsBillService;
import com.ztgf.logistics.models.bo.deppon.LogisticsBillBO;
import com.ztgf.logistics.models.dto.deppon.LogisticsBillDTO;

/**
 * 物流账单表控制器
 *
 * @author mxli
 * @Date 2021-09-13 22:14:02
 */

@RestController
@RequestMapping("/api/logisticsBill")
@Slf4j
@Api(value = "LogisticsBillApiController",tags = "物流账单表Api接口")
public class LogisticsBillApiController {

    @DubboReference
    private ILogisticsBillService logisticsBillService;
    @DubboReference
    private ISessionService sessionService;
    @DubboReference
    private IShopInfoService shopInfoService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<LogisticsBillDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        LogisticsBillDTO dto = logisticsBillService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "物流账单表列表",notes = "物流账单表列表")
    @PostMapping("/queryPageList")
    public Result<Page<LogisticsBillDTO>> queryPageList(LogisticsBillBO bo){
        UserVO userVO = sessionService.getUserVO();
        ShopInfoDTO shopInfoDTO = shopInfoService.getByUserId(userVO.getId());
        if(shopInfoDTO == null){
            return new Result<>(new Page<>());
        }
        bo.setShopId(shopInfoDTO.getId());
        return logisticsBillService.queryPageList(bo);
    }
}
